<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script language="javascript">
function editRecord(id){
    var f=document.form;
    f.method="post";
    f.action='edit.jsp?id='+id;
    f.submit();
}
function deleteRecord(id){
    var f=document.form;
    f.method="post";
    f.action='delete.jsp?id='+id;
    f.submit();
}
</script>
</head>
<body>
<form action="" method="post" name="form">
<h3>Data from the table 'REGISTRATION' of database</h3>
	<%
		try {

			String URL = "jdbc:mysql://localhost:3306/STUDENTS";

			Connection connection = null;

			PreparedStatement psmt = null;

			ResultSet rs = null;

			Class.forName("com.mysql.jdbc.Driver").newInstance();

			connection = DriverManager.getConnection(URL, "root", "sannu");

			String sql = "SELECT * from REGISTRATION";
			psmt = connection.prepareStatement(sql);
			rs = psmt.executeQuery(sql);
	%>
	<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
		<%
			while (rs.next()) {
		%>
		<TR>
			<TD><%=rs.getInt(1)%></TD>
			<TD><%=rs.getString(2)%></TD>
			<TD><%=rs.getString(3)%></TD>
			<TD><%=rs.getString(4)%></TD>
			<TD><%=rs.getString(5)%></TD>
			<TD><%=rs.getString(6)%></TD>
			<TD><%=rs.getString(7)%></TD>
			<TD><%=rs.getString(8)%></TD>
			<TD><%=rs.getString(9)%></TD>
			<TD><%=rs.getString(10)%></TD>
			<TD><%=rs.getString(11)%></TD>
			<TD><%=rs.getString(12)%></TD>
			<TD><%=rs.getString(13)%></TD>
			<TD><%=rs.getString(14)%></TD>
			<TD><%=rs.getString(15)%></TD>
			<TD><%=rs.getString(16)%></TD>
			
			<td><input type="button" name="edit" value="Edit" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="editRecord(<%=rs.getString(1)%>);" ></td>
<td><input type="button" name="delete" value="Delete" style="background-color:#ff0000;font-weight:bold;color:#ffffff;" onclick="deleteRecord(<%=rs.getString(1)%>);" ></td>
		</TR>
		<%
			}
		%>

		<%
			// close all the connections.

				rs.close();
				psmt.close();
				connection.close();
			} catch (Exception ex) {
		%>
		<font size="+3" color="red"></b> <%
 	out.println("Unable to connect to database.");
 	}
 %> </font>
 </TABLE>
	<!--<TABLE>
		<TR>
			<TD>
				<FORM ACTION="NewFile.jsp" method="get" />
				<button type="submit"><-- back</button>
			</TD>
		</TR>
	</TABLE> -->
	</form>
</body>
</html>